<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title></title>
    <style type="text/css">
        #msg{
            color: red;
        }
        #subjectForm{
            text-align: center;
            margin-top: 50px;
        }
    </style>
    <script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery-1.4.3.js"></script>
    <script>
        var nameFlag;
        var periodFlag;
        function toSubmit() {
            if(nameFlag && periodFlag){
                $("#name").val();
                $.ajax({
                    type:"POST",
                    url:"/scvs/subject/check",
                    data:{
                        name:name
                    },
                    dateType:"json",
                    success:function(data){
                        console.log(data);
                        if(data){
                            $("#subjectForm").submit();
                        }else{
                            $("#msg").text("课程已存在，请重新输入");
                        }
                    }
                });
            }else{
                $("#msg").text("还有信息未输入");
                return;
            }
        }
        function checkName(obj) {
            if (obj.value.trim() == "") {
                nameFlag = false;
                $("#msg").text("请填写课程名称");
            } else {
                nameFlag = true;
            }
        }
        function checkPeriod(obj) {
            if (obj.value.trim() == "") {
                periodFlag = false;
                $("#msg").text("请填写课时");
            } else {
                periodFlag = true;
            }
        }
    </script>
</head>
<body>
<%@include file="../common/headManager.jsp" %>
<form id="subjectForm" action="/scvs/subject/add" method="post">
    <table class="add" align="center">
        <tr>
            <td>课程名称</td>
            <td><input type="text" onblur="checkName(this)" id="name" name="subject.name"/></td>
        </tr>
        <tr>
            <td>课时</td>
            <td><input type="text" onblur="checkPeriod(this)" name="subject.period"/></td>
        </tr>
        <tr>
            <td>&nbsp;</td>
            <td><span id="msg"></span></td>
        </tr>
        <tr>
            <td colspan="2"><input type="button" onclick="toSubmit()" value="提交"/></td>
        </tr>
    </table>
</form>
</body>
</html>
